import Vue from 'vue'
import Vuex from 'vuex';
import localStore from '../js/LocalStore.js';
import Config from '@/js/conf/Config.js';
import common from './modules/common.js';

Vue.use(Vuex)

const store = new Vuex.Store({
	modules: {
		common
	},
	state: {
		hasLogin: false,
		loginProvider: "",
		testvuex: false,
		colorIndex: 0,
		colorList: ['#FF0000', '#00FF00', '#0000FF'],
		isExpand: true, //导航二三级菜单是否展开
		user: localStore.getUserInfo(),
		tabBarIds: undefined,//记录当在哪个页面，刷新窗口时用到
		compsetBaseInfo:{}
	},
	mutations: {

		async login(state, provider) {
			state.hasLogin = true;
			state.loginProvider = provider;
			await localStore.setLogin(state.hasLogin);

		},

		setTestTrue(state) {
			state.testvuex = true;
		},
		setTestFalse(state) {
			state.testvuex = false;
		},

		setColorIndex(state, index) {
			state.colorIndex = index
		},

		async setLogOut(state) {
			state.hasLogin = false;
			await localStore.setLogin(state.hasLogin);
			state.tabBarIds = undefined;
			localStore.setTabBarIds(undefined);
		},
		setIsExpand(state, value) {
			state.isExpand = value;
		},
		setTabBarIds(state, value) {
			state.tabBarIds = value;
			localStore.setTabBarIds(value);
		},

		// 设置-基础设置信息【获取】
		setCompsetBaseInfo(state, value){
			state.compsetBaseInfo = value
		}

	},
	getters: {
		hasLogin(state) {
			state.hasLogin = localStore.getLogin();
			return state.hasLogin;
		},

		currentColor(state) {
			return state.colorList[state.colorIndex]
		},
		isExpand(state) {
			return state.isExpand;
		},

		tabBarIds(state) {
			let tIds = localStore.getTabBarIds();
			if (tIds)
				state.tabBarIds = tIds;
			else
				state.tabBarIds = undefined;
			return state.tabBarIds;
		},
	},

	actions: {

		// 设置-基础设置信息【获取】
		async getCompsetBaseInfo({ commit }, data) {
			let res = await Vue.prototype.$api({ url: Config.compset_base_info, data });
			if (!res) return;
			if (res.status == 1) {
				commit('setCompsetBaseInfo', res.data);
			}
		}
	}
})

export default store
